package com.dapeis.web.wx.controller.impl;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ag.core.exception.SysTipsException;
import com.ag.core.utils.AgAssert;
import com.dapeis.domain.Collocation;
import com.dapeis.service.CollocationService;
import com.dapeis.service.TIMService;
import com.dapeis.service.UserService;
import com.dapeis.web.wx.controller.ITMController;
import com.dapeis.web.wx.controller.RestController;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

/**
 * @author 作者 E-mail: hzyuanyong@126.com
 * @version 创建时间：2017年5月17日 下午4:59:27 类说明
 */
@Controller
@RequestMapping("/wx/tim")
public class TMController extends RestController implements ITMController {

    @Resource
    TIMService timService;
    @Resource
    UserService userService;
    @Resource
    CollocationService collocationService;

    @Override
    public @ResponseBody JsonElement getSignature() {
	JsonObject json = success();
	json.add("data", timService.getWxUserSignature(getThreadLocalUser()));
	return json;
    }

    @Override
    public JsonElement addFriend(@RequestParam Integer collocationId,
	    HttpServletRequest request) {
	Collocation collocation = collocationService
		.selectByPrimaryKey(collocationId);
	AgAssert.notNull(collocation, SysTipsException.class, "查询不到搭配师信息:"
		+ collocationId);
	JsonObject json = success();
	timService.addFriend(collocationId, getThreadLocalUserId());
	return json;
    }

}
